package com.cheng.example.book.advise151.chap1.client13;

import com.cheng.example.book.advise151.chap1.client11.SerializationUtils;

import java.io.Serializable;


/**
 *
 * 建议13：避免为final变量复杂赋值
 *
 * 通过构造函数为final变量赋值
 * 通过方法返回值为final变量赋值
 * final修饰的属性不是基本类型
 *
 * 这段讲的很精辟
 */


public class Person implements Serializable {
    private static final long serialVersionUID = 1867341609628930239L;
    //通过方法返回值为final变量赋值
    public final String pName = initName();

    public String initName() {
        return "程咬金";
    }


    public static void main(String[] args) {
        SerializationUtils.writeObject(new Person());
        Person person= (Person) SerializationUtils.readObject();
        System.out.println(person);
    }
}